/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 * 用户输入
 * 随机产生
 * 比较并输出
 * 
 */

package lottery_win;
import java.io.*;
/**
 *
 * @author hhl
 */
public class Lottery_win {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int code1=0,code2=0,code3=0;
        int firstPrize=0,secondPrize=0,thirdPrize=0;
        String s="";
        for(int i = 1; i <= 3; i++){

            //gambler wager
            System.out.println("请输入3个在1~20内的号码：");
            try{
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                s = in.readLine();
            }
            catch(IOException e){}

            //... and produce jackpot
            switch(i){
                case 1:
                    code1=Integer.parseInt(s);

                    firstPrize=Produce();
                    break;
                case 2:
                    code2=Integer.parseInt(s);

                    secondPrize=Produce();
                    while(secondPrize==firstPrize){
                        secondPrize=Produce();
                    }
                    break;
                case 3:
                    code3=Integer.parseInt(s);

                    thirdPrize=Produce();
                    while(thirdPrize==firstPrize||thirdPrize==secondPrize){
                        thirdPrize=Produce();
                    }
                    break;
                default:
                    break;
            }
        }

        //publicity
        System.out.println("你输入的号码为："+code1+", "+code2+", "+code3+".");
        System.out.println("开奖号码为："+firstPrize+", "+secondPrize+", "+thirdPrize+".");

        // compare
        boolean result1=false,result2=false,result3=false;
        for(int j = 1; j<=3; j++){
            result1 = Compare(code1,firstPrize) ||Compare(code2,firstPrize) ||Compare(code3,firstPrize);
            result2 = Compare(code1,secondPrize)||Compare(code2,secondPrize)||Compare(code3,secondPrize);
            result3 = Compare(code1,thirdPrize) ||Compare(code2,thirdPrize) ||Compare(code3,thirdPrize);
        }
        if(result1)
            System.out.println("Congradulation! You win the first prize!");
        if(result2)
            System.out.println("Congradulation! You win the second prize!");
        if(result2)
            System.out.println("Congradulation! You win the third prize!");
        if(result1||result2||result3)
            System.out.println("What's a pity! You lose.");
    }
    static int Produce(){
        return (int)(Math.random()*(20-1)+1);
    }
    static boolean Compare(int lotteryNumber, int randomNumber){
        if(lotteryNumber==randomNumber)
            return true;
        return false;
    }
}
